// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
//
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.warehouse.viewers.csv;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.dengues.commons.utils.FileUtils;
import org.dengues.core.warehouse.ENodeCategoryName;
import org.dengues.model.database.DatabaseDiagram;
import org.dengues.warehouse.viewers.wizards.NewElementWizardPage2;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-7-4 qiang.zhang $
 * 
 */
public class NewCSVWizardPage2 extends NewElementWizardPage2 {

    private Text fileText;

    /**
     * Qiang.Zhang.Adolf@gmail.com NewCSVWizardPage2 constructor comment.
     * 
     * @param path
     * @param database
     */
    public NewCSVWizardPage2(IPath path, DatabaseDiagram database, ENodeCategoryName name) {
        super(path, database, name);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.warehouse.viewers.wizards.NewElementWizardPage2#createControl(org.eclipse.swt.widgets.Composite)
     */
    @Override
    public void createControl(Composite parent) {
        super.createControl(parent);
        fileText = new Text(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
        fileText.setEditable(false);
        fileText.setLayoutData(new GridData(GridData.FILL_BOTH));
        if (database != null) {
            databaseName = (String) database.getProperties().get("FILENAME");
            setFileName(databaseName);
            setPageComplete(true);
        } else {
            setPageComplete(false);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.warehouse.viewers.wizards.NewElementWizardPage2#setFileName(java.lang.String)
     */
    @Override
    protected void setFileName(String open) {
        if (open != null) {
            nameText.setText(FileUtils.getPortablePath(open));
            try {
                fileText.setText(FileUtils.getStringFromStream(new FileInputStream(open)));
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            }
        }
    }

}
